<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Role_model extends CI_Model
{
    public function __construct()
    {
        parent::__construct();
    }
    public function search_role($name,$desc){
      $sql;
        if($desc != "" && $name != ""){
          $sql = "SELECT * FROM app_roles WHERE role_name LIKE ".$this->db->escape($name)." AND description LIKE '".$desc."' ";
        }else if($name != "" && $desc == ""){
          $sql = "SELECT * FROM app_roles WHERE role_name LIKE ".$this->db->escape($name)." ";
        }else{
          $sql = "SELECT * FROM app_roles WHERE description LIKE ".$this->db->escape($desc)." ";
        }
      $query = $this->db->query($sql);
      if($query->num_rows() != 0){
        return $query->result();
      }
      else {
        $result = "No results found.";
        return $result;
      }
    }
    public function updateRoleData($data){
      $this->db->query("call app_roles_upd(?,?,?,?,?,@err,@msg)",$data);
      $que = $this->db->query("SELECT @err as error , @msg as msg");
      return $que->result();
    }

    public function insertRoleDtl($data){
        $this->db->query('call app_role_dtl_ins(?,?,?,?,?,?,?,?,@err,@msg)',$data);
        $query = $this->db->query("SELECT @err as error , @msg as msg");
        return $query->result();
    }

    public function getRoleDtl($id){
        $this->db->where('role_id',$id);
        $query = $this->db->get('app_role_details_v');
        return $query->result();
    }

    public function updateRoleDtl($data){
        $this->db->query('call app_role_dtl_upd(?,?,?,?,?,?,?,?,@err,@msg)',$data);
        $query = $this->db->query("SELECT @err as error , @msg as msg");
        return $query->result();
    }

    public function getROleData($id){
        $this->db->where('role_id',$id);
        $query = $this->db->get('app_roles_v');
        return $query->result();
    }

    public function getRoleCB($rid,$fid){
      $this->db->where('role_id',$rid);
      $this->db->where('form_id',$fid);
      $query = $this->db->get('app_role_details_v');
      return $query->result();
    }

    public function delRoleDtl($data){
        $this->db->query('call app_role_dtl_del(?,?,@err,@msg)',$data);
        $query = $this->db->query("SELECT @err as error , @msg as msg");
        return $query->result();
    }


}